package com.config;

import com.common.CommonController;
import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.ext.handler.ContextPathHandler;
import com.jfinal.ext.interceptor.SessionInViewInterceptor;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.jfinal.render.FreeMarkerRender;
import com.model._MappingKit;
import com.business.section.controller.SectionController;
import com.business.sectiondetail.controller.SectionDetailController;
import com.business.user.controller.UserController;

/**
 * <p>Title:DefaultConfig</p>
 * <p>Description:DefaultConfig extends JFinalConfig</p>
 * @author qing
 * @version 1.0
 * API引导式配置
 */
public class DefaultConfig extends JFinalConfig {

	/**
	 * 配置常量
	 */
	@Override
	public void configConstant(Constants me) {
		// TODO Auto-generated method stub
		PropKit.use("db_config.properties");
		me.setDevMode(PropKit.getBoolean("devMode", true));
		FreeMarkerRender.setProperty("classic_compatible", "true");
		me.setEncoding("UTF-8");
		me.setBaseUploadPath(PropKit.get("uploadFileUrl"));//上传文件路径
		me.setMaxPostSize(20*1024*1024);//post最大值20M
	}
	/**
	 * 配置路由
	 */
	@Override
	public void configRoute(Routes me) {
		//设置为路径路由
		me.add("/", IndexController.class);  
		//用户
		me.add("/login",UserController.class,"/web/user");
		//公共路由
		me.add("/common", CommonController.class);
		
		//帖子
		me.add("/section",SectionController.class,"/web/section");
		
		//回帖子
		me.add("/sectiondetail",SectionDetailController.class,"/web/sectiondetail");
	}

	/**
	 * 配置插件
	 */
	@Override
	public void configPlugin(Plugins me) {
		// 配置C3p0数据库连接池插件
		String jdbcUrl = PropKit.get("jdbcUrl");
		String user = PropKit.get("user");
		String password = PropKit.get("password").trim();
		C3p0Plugin cp = new C3p0Plugin(jdbcUrl,user,password);
		me.add(cp);
		// 配置ActiveRecord插件
		ActiveRecordPlugin arp = new ActiveRecordPlugin(cp);
		me.add(arp);
		// 所有配置在 MappingKit 中搞定,进行DB映射  
		_MappingKit.mapping(arp);
		
	}

	
	/**
	 * 配置全局拦截器
	 */
	@Override
	public void configInterceptor(Interceptors me) {
		// TODO Auto-generated method stub
		me.add(new SessionInViewInterceptor());
	}
	/**
	 * 配置处理器
	 */
	@Override
	public void configHandler(Handlers me) {
		// TODO Auto-generated method stub
		me.add(new ContextPathHandler("contextPath"));
		
	}

}
